﻿using SUNRPA.CONTROLS.IMPL.domain;
using SUNRPA.CONTROLS.IMPL.domain.constant;
using SUNRPA.CONTROLS.IMPL.domain.flowItemParam;
using SUNRPA.CONTROLS.IMPL.domain.flowRunningVar;
using SUNRPA.CONTROLS.IMPL.util;
using System.Collections.Concurrent;

namespace SUNRPA.CONTROLS.IMPL.controls {
    public class SetVarNAction:BaseControlActions {
        public override int Execute(int currentIndex, FlowItem item, ConcurrentDictionary<string, ConcurrentDictionary<string, RPAVariableDefineWrapper>> globleData, List<FlowItem> flowItems) {
            SetVarNParam? param = item.ControlParam as SetVarNParam;

            string outVarName = param.VarName;
            this.GetStringVar(ref outVarName, globleData);

            VarialbleType vt = param.Vt;

            string variableValue = param.VariableValue;
            this.GetStringVar(ref variableValue, globleData);

            this.saveVar(globleData, outVarName, RPAVariable.CreateVar(outVarName, vt, variableValue), DefaultContents.RUNNING_PARAM);
            return currentIndex;
        }
    }
}
